<template>
	<view class="user-invite-app" style="text-align: center;">
		<view style="margin-bottom: 20upx;">推广二维码</view>
		<view>
			<image :src="qrcodeUrl" style="width:500upx;height:500upx;background-color: #eee;"></image>
		</view>
		<view class="share-btn btn btn-primary" @click="shareQrcode">分享给好友</view>
	</view>
</template>

<script>
	import util from '@/libs/util.js'
	import globalConfig from '@/config'
	import MyTabs from '@/components/my-tabs.vue'
	import uniLoadMore from '@/components/uni-load-more/uni-load-more.vue'
	const baseHttp = globalConfig.API_HOST
	
	export default {
		data() {
			return {
				tab: {
					current: null,
					items: [
						{value:null,label:'茶室消费'}
					]
				},
				baseHttp: 'baseHttp',
				qrcodeUrl: '',
				listData: {
					status: "loading",
					loading: false,
					perpage: 10,
					count: 0,
					page: 1,
					sortby: '',
					sortmethod: '',
					selectIds: [],
					itemIdField: 'id',
					items: [
					]
				}
			};
		},
		onLoad(e) {	

		},
		onShow() {
			this.getQrcodeData()
		},
		onReachBottom() {

		},
		components: {
			MyTabs,
			uniLoadMore
		},
		methods: {
			...util,
			shareQrcode() {
				/*
				uni.share({
				    provider: "weixin",
				    scene: "WXSceneSession",
				    type: 2,
				    imageUrl: this.qrcodeUrl,
				    success: function (res) {
				        console.log("success:" + JSON.stringify(res));
				    },
				    fail: function (err) {
				        console.log("fail:" + JSON.stringify(err));
				    }
				});
				*/
				var that = this
				uni.downloadFile({
				    url: this.qrcodeUrl,
				    success (res) {
				        if (res.statusCode === 200) {
				            //that.wxCode = res.tempFilePath
							
							uni.saveImageToPhotosAlbum({ 
							  filePath: res.tempFilePath,
							  success(res) {
									console.log('保存成功');
									uni.showModal({
										 title: '保存成功',
										 content: '图片成功保存到相册了，快去发朋友圈吧~',
										 showCancel: false,
										 confirmText: '确认',
										 confirmColor: '#21e6c1',
										 success: function (res) {
											   if (res.confirm) {
												   console.log('用户点击确定');
											   }
										 }
									})
							   },
							   fail(res) {
								   console.log(res);
							   }
							})
						}
					},
					fail(res) {
						console.log(res);
					}
				});
				
			},
			getQrcodeData() {
				uni.showLoading({
					title: '加载中'
				});
				this.$api.post('/user/getInviteQRCode', {
					
				}).then((response) => {
					this.qrcodeUrl = baseHttp + '/' + response.data;
					uni.hideLoading()
				})
			},
			goPage(url) {
				uni.navigateTo({
					url: url
				})
			}
		}
	}
</script>

<style lang="scss">
	page{
		background-color: $uni-bg-color-grey;
	}
	.user-invite-app{
		font-size:32upx;
		.share-btn{
			margin:30upx;
			padding:20upx;
		}
		.share{
			
		}
		.items{
			
			.item{
				background-color: white;
			}
			.fields{
				padding: 10upx;
				.field{
					padding: 10upx;
					display: flex;
					.title{
						width:150upx;
					}
					.value{
						
					}
				}
			}
			
			.item{
				/*margin-right:30upx;*/
				margin-bottom:30upx;
				margin-top:30upx;
				border-bottom: 1upx solid #eee;
				padding-bottom: 20upx;
				.info{
					margin-left:20upx;
					display: flex;
					.title{
						font-weight: bold;
						flex:1;
					}
					.intro{
						color:#929292;
					}
					.up{
						color:green;
					}
					.down{
						color:red;
					}
				}
				.date{
					color:#929292;
					text-align: right;
				}
			}
		}
	}

</style>
